/***************
 * Project Summary Panel
 */
AIR2.Project.Summary = function() {
    return new AIR2.UI.Panel({
        storeData: AIR2.Project.SUMMDATA,
        url: AIR2.HOMEURL + '/project',
        colspan: 1,
        title: 'Summary',
        iconCls: 'air2-project-summary-icon',
        itemSelector: '.air2-project-summary',
        tpl: new Ext.XTemplate(
            '<tpl for="."><div class="air2-project-summary">' +
              '<b>{prj_display_name}</b>' +
              '<p>{prj_desc}</p>' +
              '<ul class="air2-project-sharing"><li>Shared?</li>{[this.formatShared(values.prj_shared_flag)]}</ul>' +
              '<ul class="air2-project-status"><li>Status</li>{[this.formatStatus(values.prj_status)]}</ul>' +
              '<div class="dates"><span class="meta">Created by {[AIR2.Format.userName(values.CreUser, true)]} ' +
                'on {[AIR2.Format.date(values.prj_cre_dtim)]}</span></div>' +
              '{[this.formatUpdated(values)]}' +
            '</div></tpl>',
            {
                compiled: true,
                disableFormats: true,
                formatShared: function(isShared) {
                    if (isShared) return '<li class="green">Yes</li>';
                    else return '<li class="red">No</li>';
                },
                formatStatus: function(status) {
                    if (status == 'A') return '<li class="green">Active</li>';
                    else return '<li class="red">Inactive</li>';
                },
                formatUpdated: function(values) {
                    if (!values.UpdUser || !values.prj_upd_dtim) return '';
                    var str = '<div class="dates"><span class="meta">';
                    str += 'Last updated by ' + AIR2.Format.userName(values.UpdUser, true);
                    str += ' on ' + AIR2.Format.date(values.prj_upd_dtim) + '</span></div>';
                    return str;
                }
            }
        ),
        listeners: {
            aftersave: function(form, rs) {
                Ext.getCmp('air2-app').showLocation('Project: '+rs[0].get('prj_name'));
            }
        },
        allowEdit: AIR2.Project.SUMMDATA.authz.may_manage,
        editInPlace: [{
            xtype: 'textfield',
            fieldLabel: 'Display Name',
            name: 'prj_display_name',
            allowBlank: false,
            msgTarget: 'under'
        },{
            xtype: 'air2remotetext',
            fieldLabel: 'Url Name',
            name: 'prj_name',
            allowBlank: false,
            remoteUrl: AIR2.HOMEURL + '/project/name.json',
            msgTarget: 'under',
            maskRe: /[a-z0-9_\-]/
        },{
            xtype: 'textarea',
            fieldLabel: 'Summary',
            name: 'prj_desc',
            height: 100
        },{
            xtype: 'air2combo',
            fieldLabel: 'Shared',
            name: 'prj_shared_flag',
            width: 60,
            choices: [[true, 'Yes'], [false, 'No']]
        },{
            xtype: 'air2combo',
            fieldLabel: 'Status',
            name: 'prj_status',
            width: 90,
            choices: [['A', 'Active'], ['F', 'Inactive']]
        }] //end editInPlace
    });
}